package org.linlinjava.litemall.admin.controller;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.beans.dto.AdminOrderAcceptAuditVo;
import org.linlinjava.litemall.admin.beans.dto.PurchaseDto;
import org.linlinjava.litemall.admin.beans.vo.AdminOrderVo;
import org.linlinjava.litemall.admin.service.AdminAdminOrderService;
import org.linlinjava.litemall.core.validator.Order;
import org.linlinjava.litemall.core.validator.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 管理员管理订单控制器
 *
 * @author yliyun
 * @date 2022/09/14
 */
@Api(tags = "管理员管理订单API")
@RestController
@RequestMapping("/admin/shopOrder")
@Validated
public class AdminAdminOrderController {

    @Autowired
    private AdminAdminOrderService adminAdminOrderService;

    @ApiOperation("货品列表")
    @GetMapping("/merchandiseList")
    @LogAnno
    public Object merchandiseList(
            Integer orderStatus,
            @LoginAdminShopId Integer shopId,
            String startDate,
            String endDate,
            Integer serverType,
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit) {
        return adminAdminOrderService.merchandiseList(orderStatus, startDate, endDate, shopId, page, limit,serverType);
    }

    @ApiOperation("入库列表")
    @GetMapping("/list")
    @LogAnno
    public Object list(String orderSn, String userName, String address,
                       Integer orderStatus,
                       @LoginAdminShopId Integer shopId,
                       String startDate,
                       String endDate,
                       Integer serverType,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "add_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        return adminAdminOrderService.list(orderStatus, startDate, endDate, orderSn, userName, address, shopId, page, limit, sort, order,serverType);
    }



    /**
     * 订单申请
     *
     * @param adminOrderVo 管理秩序签证官
     * @param shopId       商店id
     * @return {@link Object}
     */
    @PostMapping("/orderApplying")
    @LogAnno
    public Object orderApplying(@RequestBody AdminOrderVo adminOrderVo, @LoginAdminShopId Integer shopId){
        adminOrderVo.setShopId(shopId);
        return adminAdminOrderService.orderApplying(adminOrderVo);
    }

    @ApiOperation("审核通过")
    @GetMapping("/orderHqPass")
    @LogAnno
    public Object orderHqPass(@NotNull @RequestParam("id") Integer id, @RequestParam("remark") String remark){
        return adminAdminOrderService.orderHqPass(id, remark);
    }

    @ApiOperation("审核驳回")
    @GetMapping("/orderHqNoPass")
    public Object orderHqNoPass (@NotNull @RequestParam("id") Integer id, @RequestParam("remark") String remark){
        return adminAdminOrderService.orderHqNoPass(id, remark);
    }

    @ApiOperation("同意调货")
    @GetMapping("/orderPass")
    @LogAnno
    public Object orderPass(@NotNull @RequestParam("id") Integer id, @RequestParam("remark") String remark){
        return adminAdminOrderService.orderPass(id, remark);
    }

    @ApiOperation("不同意调货")
    @GetMapping("/orderNoPass")
    public Object orderNoPass (@NotNull @RequestParam("id") Integer id, @RequestParam("remark") String remark){
        return adminAdminOrderService.orderNoPass(id, remark);
    }

    /**
     * 订单支付
     * 支付货款
     *
     * @param adminOrderVo 管理秩序签证官
     * @param shopId       商店id
     * @return {@link Object}
     */
    @PostMapping("/orderPay")
    @LogAnno
    public Object orderPay(@RequestBody AdminOrderVo adminOrderVo, @LoginAdminShopId Integer shopId){
        adminOrderVo.setShopId(shopId);
        return adminAdminOrderService.orderPay(adminOrderVo);
    }

    /**
     * 发货
     * 同意发货
     *
     * @param adminOrderVo 管理秩序签证官
     * @return {@link Object}
     */
    @PostMapping("/deliverGoods")
    @LogAnno
    public Object deliverGoods(@RequestBody AdminOrderVo adminOrderVo){
        return adminAdminOrderService.deliverGoods(adminOrderVo);
    }

    /**
     * 取消发货
     * 拒绝发货
     *
     * @param adminOrderVo 管理秩序签证官
     * @return {@link Object}
     */
    @PostMapping("/cancelDeliverGoods")
    @LogAnno
    public Object cancelDeliverGoods(@RequestBody AdminOrderVo adminOrderVo){
        return adminAdminOrderService.cancelDeliverGoods(adminOrderVo);
    }


    /**
     * 提货
     * 确认收货
     *
     * @param adminOrderVo 管理秩序签证官
     * @param shopId       商店id
     * @return {@link Object}
     */
    @PostMapping("/takeDelivery")
    @LogAnno
    public Object takeDelivery(@RequestBody AdminOrderVo adminOrderVo, @LoginAdminShopId Integer shopId){
        adminOrderVo.setShopId(shopId);
        return adminAdminOrderService.takeDelivery(adminOrderVo);
    }

    /**
     * 读
     * 门店订单详情
     *
     * @param id     id
     * @param shopId 商店id
     * @return {@link Object}
     */
    @GetMapping("/read")
    @LogAnno
    public Object read(@NotNull  @RequestParam(value = "id") Integer id, @LoginAdminShopId Integer shopId){
        return adminAdminOrderService.read(id, shopId);
    }

    /**
     * 采购申请
     *
     * @param purchaseDto 购买dto
     * @param shopId      商店id
     * @return {@link Object}
     */
    @PostMapping("/purchaseApplying")
    @LogAnno
    public Object purchaseApplying(@Valid @RequestBody PurchaseDto purchaseDto, @LoginAdminShopId Integer shopId){
        purchaseDto.setShopId(shopId);
        return adminAdminOrderService.purchaseApplying(purchaseDto);
    }

    /**
     * 接受审计
     * 收货审核申请
     *
     * @param adminOrderAcceptAuditVo 管理订单接受审计签证官
     * @param shopId                  商店id
     * @return {@link Object}
     */
    @PostMapping("/acceptAudit")
    @LogAnno
    public Object acceptAudit(@RequestBody AdminOrderAcceptAuditVo adminOrderAcceptAuditVo, @LoginAdminShopId Integer shopId){
    	adminOrderAcceptAuditVo.setShopId(shopId);
    	return adminAdminOrderService.acceptAudit(adminOrderAcceptAuditVo);
    }

    /**
     * 通过审计
     * 通过审核
     *
     * @param id     id
     * @param remark 备注
     * @return {@link Object}
     */
    @GetMapping("/passAudit")
    @LogAnno
    public Object passAudit(@NotNull @RequestParam("id") Integer id, @RequestParam("remark") String remark){
    	return adminAdminOrderService.passAudit(id, remark);
    }

   @ApiOperation("拒绝收货")
    @GetMapping("/noPassAudit")
    @LogAnno
    public Object noPassAudit(@NotNull @RequestParam("id") Integer id, @RequestParam("remark") String remark){
    	return adminAdminOrderService.noPassAudit(id, remark);
    }

}
